<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
  <script type="text/javascript">
      var gitProjectTable;
      var selectType = "multiple";
  </script>
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <!-- 当前位置 begin -->
        <div class="row h-home-path">
          <div class="col-md-12">
            <ol class="breadcrumb">
              <li><i class="fa fa-home"></i>&nbsp;&nbsp;所在位置</li>
              <li>首页</li>
              <li class="active">git项目信息</li>
            </ol>
          </div>
        </div>
        <!-- 当前位置 end -->

        <!-- 查询筛选内容 bagin -->
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="col-md-1 col-sm-1 col-xs-1 text-right">
              <label class="control-labe h-form-label" for="projectCode">项目编码：</label>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-2">
              <input class="form-control" id="projectCode" name="projectCode" type="text" value="">
            </div>
            <div class="col-md-1 col-sm-1 col-xs-1 text-right">
              <label class="control-labe h-form-label" for="projectName">项目名称：</label>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-2">
              <input class="form-control" id="projectName" name="projectName" type="text" value="">
            </div>
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" onclick="GitProjectManager.search()" type="button"><i class="fa fa-search">&nbsp;&nbsp;</i>查询
              </button>
              <button class="btn btn-info" onclick="GitProjectManager.downloadCode()" type="button"><i
                      class="fa fa-sync">&nbsp;&nbsp;</i>同步代码
              </button>
              <button class="btn btn-info" onclick="GitProjectManager.newBranch()" type="button"><i
                      class="fa fa-sync">&nbsp;&nbsp;</i>新建分支
              </button>
              <@permission btnType="add" btnId="addBtn" btnValue="新增" op="git:project:add"
              btnMethod="GitProjectManager.addGitProject()"/>
              <div id="btnPermission" style="display:none">
                <div class="h-btn-group">
                  <@permission btnType="edit" btnLink="true" btnValue="修改" btnClass="btn btn-info" btnId="editBtn"
                  op="git:project:edit"/>
                  <@permission btnType="delete" btnLink="true" btnValue="删除" btnId="deleteBtn" btnClass="btn btn-danger"
                  op="git:project:del"/>
                  <@permission btnType="view" btnLink="true" btnValue="查看" btnId="viewBtn" btnClass="btn btn-warning"
                  op="git:project:view"/>
                </div>
              </div>
              <button class="btn btn-default" type="reset"><i class="fa fa-mail-reply">&nbsp;&nbsp;</i>重置</button>
            </div>
          </form>
        </div>

        <!-- 表格 begin -->
        <div class="panel panel-white h-panel">
          <div class="panel-body">
            <table class="table table-striped table-bordered table-hover text-center" id="gitProject_table"
                   style='width:100%'></table>
          </div>
        </div>
        <!-- 表格 end -->
      </div>
    </div>
    <!-- end: PAGE -->
  </div>
  <!-- end: MAIN CONTAINER -->
  <!-- 新增 end -->
  <!-- end: SUBVIEW SAMPLE CONTENTS -->
</div>
<#include "/common/jslib.html">

<script type="text/javascript">
    $(function () {
        GitProjectManager = {
            init: function () {

            },
            search: function () {
                var queryCond = {
                    projectName: $("#projectName").val()
                    , projectCode: $("#projectCode").val()
                };
                gitProjectTable.options.queryCond = queryCond;
                var tableId = gitProjectTable.options.tableId;
                $(tableId).DataTable().draw();
            },
            addGitProject: function () {
                window.location.href = "/gitProject/to-form?operation=add";
            },
            handleOperate: function (operate, id) {
                if (operate == "delete") {
                    GitProjectManager.deleteGitProject(id);
                } else if (operate == "edit" || operate == "view") {
                    window.location.href = "/gitProject/to-form?operation=" + operate +
                        "&id=" + id;
                }
            },
            deleteGitProject: function (id) {
                var url = "/gitProject/delete";
                var data = {
                    "id": id
                };
                Jmts.deleteItem("确认要删除吗？", url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips("删除成功");
                      GitProjectManager.search();
                    }
                });
            },
            downloadCode: function () {
                var chk_value = [];
                $('input[name="gitProject_select"]:checked').each(function () {
                    chk_value.push($(this).val());
                });
                if (chk_value.length == 0) {
                    Jmts.alert("请选择要同步代码的git项目");
                    return false;
                }
                Jmts.confirm("确定要同步代码到本地吗？", function () {
                    var url = "/gitProject/downloadCode";
                    var data = {
                        projectIds: chk_value
                    }
                    Jmts.ajaxPost(url, data, function (result) {
                        if (result.success) {
                            Jmts.alert("同步代码成功，代码路径：" + result.localCodePath);
                        } else {
                            Jmts.errorTips(result.msg);
                        }
                    })
                });
            },
            newBranch: function () {
                var chk_value = [];
                $('input[name="gitProject_select"]:checked').each(function () {
                    chk_value.push($(this).val());
                });
                if (chk_value.length == 0) {
                    Jmts.warnTips("请选择要新建分支的记录");
                    return false;
                }
                var projectIds = chk_value.join(",");
                var url = "/gitProject/to-newBranch?projectIds=" + projectIds;
                Jmts.openDialog("newBranch", url, "新建分支", 0, 0, 32);
            }
        }
        GitProjectManager.init();
    });
</script>
<!-- 弹窗下拉 -->
<script type="text/javascript">
    (function () {
        // datatable插件
        gitProjectTable = new mi.datatable({
            tableId: '#gitProject_table',
            headerList: [
                '选择',
                '项目编码',
                '项目名称',
                '项目 git url',
                '本地路径',
                '操作'
            ],
            headerName: [
                'chooseBox',
                'projectCode',
                'projectName',
                'remoteRepoUri',
                'localRepoPath',
                'operate'
            ],
            ajaxUrl: '/gitProject/listGitProject',
            queryCond: function () {

            },
            columnDefs: [
                {targets: 0, orderable: false}
            ],
            createdRow: function (row, data, dataIndex) {
                $(row).children('td').eq(1).attr('style',
                    'text-align:left;');
                $(row).children('td').eq(2).attr('style',
                    'text-align:left;');
                $(row).children('td').eq(3).attr('style',
                    'text-align:left;');
                $(row).children('td').eq(4).attr('style',
                    'text-align:left;');
            },
            dataSrc: function (data) {
                for (var i in data) {
                    var id = data[i]['id'];
                    if ($("#editBtn") != null && $("#editBtn") != undefined) {
                        $("#editBtn").attr("href", "javascript:GitProjectManager.handleOperate('edit', '" + id + "')");
                    }
                    if ($("#deleteBtn") != null && $("#deleteBtn") != undefined) {
                        $("#deleteBtn").attr("href", "javascript:GitProjectManager.handleOperate('delete','" + id + "')");
                    }
                    if ($("#viewBtn") != null && $("#viewBtn") != undefined) {
                        $("#viewBtn").attr("href", "javascript:GitProjectManager.handleOperate('view','" + id + "')");
                    }
                    data[i]['operate'] = $("#btnPermission").html();
                    var checkboxDtr = mi.markLink({
                        href: 'javascript:void(0)',
                        txt: selectType == "multiple" ?
                            "<input type='checkBox' id='gitProject_select' name='gitProject_select' value='" + id + "'/>" :
                            "<input type='radio' id='gitProject_select' name='gitProject_select' value='" + id + "'/>",
                        className: 'js-del-row-btn',
                        data: [
                            {id: id}
                        ]
                    });
                    data[i]['chooseBox'] = checkboxDtr;
                }
                return data;
            }
        });
    })();
</script>
</body>
</html>
